"""
project: apiAutoTestWeb
file: models.py
author: zy7y
date: 2021/4/17
"""
from tortoise import fields
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.models import Model


class User(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255, description="用户昵称")
    username = fields.CharField(max_length=255, unique=True, description="用户名")
    password = fields.CharField(max_length=255, description="用户密码")
    avatar = fields.CharField(max_length=255, default="/static/default.jpg", description="用户头像")
    created_at = fields.DatetimeField(auto_now_add=True)
    modified_at = fields.DatetimeField(auto_now=True)

    # class PydanticMeta:
    #     # 返回的时候不显示该字段
    #     exclude = ["password_hash"]


# 返回模型
User_Pydantic = pydantic_model_creator(User, name="User", exclude=["password"])

# 输入模型 exclude_readonly 只读字段 非必填
UserIn_Pydantic = pydantic_model_creator(User, name="UserIn", exclude=["avatar"], exclude_readonly=True)
